<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客系统登录</title>
    <script src="js/jquery.min.js"></script>
    
    <style>
        * {
            padding: 0;
            margin: 0;
            outline: none;
        }
 
        body {
            background: linear-gradient(45deg, #fbda61, #ff5acd);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
 
        .shell,
        .login-box {
            position: relative;
        }
 
        .shell {
            display: flex;
            justify-content: center;
        }
 
        .login-box {
            width: 562px;
            height: 520px;
            background-color: #fff;
            box-shadow: 0px 15px 40px #b6354e;
            border-radius: 15px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
 
        #img-box {
            width: 330px;
            height: 520px;
        }
 
        #img-box img {
            height: 100%;
			margin-left: -175px;
			border-radius: 20px;
        }
 
        #form-body {
            width: 320px;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }
 
        #welcome-lines {
            width: 100%;
            text-align: center;
            line-height: 1;
        }
 
        #w-line-1 {
            color: #7f7f7f;
            font-size: 50px;
        }
 
        #w-line-2 {
            color: #9c9c9c;
            font-size: 30px;
            margin-top: 17px;
        }
 
        #input-area {
            width: 100%;
            margin-top: 40px;
        }
 
        .f-inp {
            padding: 13px 25px;
            border: 2px solid #6e6d6d;
            line-height: 1;
            border-radius: 20px;
            margin-bottom: 15px;
        }
 
        .f-inp input {
            width: 100%;
            font-size: 14px;
            padding: 0;
            margin: 0;
            border: 0;
        }
 
        .f-inp input::placeholder {
            color: #b9b9b9;
        }
 
        #submit-button-cvr {
            margin-top: 20px;
        }
 
        #submit-button {
            display: block;
            width: 100%;
            color: #fff;
            font-size: 14px;
            margin: 0;
            padding: 14px 40px;
            border: 0;
            background-color: #f5506e;
            border-radius: 25px;
            line-height: 1;
            cursor: pointer;
        }
 
        #forgot-pass {
            text-align: center;
            margin-top: 10px;
        }
 
        #forgot-pass a {
            color: #868686;
            font-size: 12px;
            text-decoration: none;
        }
        

        #blog-home {
    position: absolute;
    top: 35px;
    right: 30px; /* 修改为右侧对齐 */
}

#blog-home a{
    color: #000; /* 修改文字颜色为黑色 */
    text-decoration: none;
    font-size: 18px;
    font-weight: bold;
}

#login{
    position: absolute;
    top: 30px;
    left: 30px; /* 修改为左侧对齐 */
}

#login a{
    color: #000; /* 修改文字颜色为黑色 */
    text-decoration: none;
    font-size: 16px;
}

#top-right {
    position: absolute;
    top: 10px;
    right: 10px;
}

#top-right a {
    display: inline-block; /* 设置为块级元素 */
    margin-left: 10px; /* 左右间距 */
    padding: 8px 12px; /* 内边距 */
    color: #000; /* 文字颜色 */
    font-size: 16px; /* 字体大小 */
    text-decoration: none; /* 去除下划线 */
    border-radius: 4px; /* 圆角 */
    background-color: #ddd; /* 背景颜色 */
}

#top-right a:hover {
    color: #fff; /* 鼠标悬停时文字颜色 */
    background-color: #333; /* 鼠标悬停时背景颜色 */
}

    </style>
</head>
 
<body>

    <div id="top-right">
        <a href="blog_list.html" class="btn">博客主页</a>
        <a href="reg2.html" class="btn">注册</a>
    </div>
    
    

    <div class="shell">
        <div id="img-box">
            <img src="img/logo6.png" alt="">
        </div>
        <div class="login-box">
            <div id="form-body">
                <div id="welcome-lines">
                    <div id="w-line-1">Hi,清欢</div>
                    <div id="w-line-2">Welcome Back</div>
                </div>
                <div id="input-area">
                    <div class="f-inp">
                        <input type="text" placeholder="user name" id="username">
                    </div>
                    <div class="f-inp">
                        <input type="password" placeholder="Password" id="password">
                    </div>

                    <div class="f-inp">
                        <input id="code_input" style="width: 80px;" placeholder="验证码">
                        
                    </div>
                    <div>
                        <img onclick="refreshCode()" id="codeimg"
                            style="display:none;height: 50px;width: 320px;">
                    </div>
                </div>
                <div id="submit-button-cvr">
                    <button type="submit" id="submit-button" onclick="mysub()">LOGIN</button>
                </div>
                <div id="forgot-pass">
                    <a href="forgot.html">Forgot password ?</a>
                </div>
            </div>
        </div>
    </div>

    <script>
        var count=0; // 记录错误登陆次数
        // 加载验证码
        function initCode(){
            jQuery.ajax({
                url:"/user/getcode",
                type:"POST",
                data:{ },
                success:function(res){
                    if(res.code==200 && res.data.length>0){
                      jQuery("#codeimg").attr("src",res.data);
                      jQuery("#codeimg").show();
                    }
                }
            });  
        }
        
        initCode();

        function refreshCode(){
            initCode();
        }


        function mysub() {
            // 1. 数据校验
            // 1.1 获取标签
            var username = jQuery("#username");
            var password = jQuery("#password");
            var code_input = jQuery("#code_input");
            // 1.2 用户名判断
            if(username.val().trim() == "") {
                alert("请输入用户名!");
                username.focus();
                return false;
            }

            // 1.3 密码判断
            if(password.val().trim() == '') {
                alert("请输入密码!");
                password.focus();
                return false;
            }

            // 冻结提交
            jQuery("#submit-button").attr("disabled", "disabled");

            // 3. 发送数据给后端
            jQuery.ajax({
                url:"/user/login",
                type:"post",
                data:{
                    'username':username.val().trim(),
                    'password':password.val().trim(),
                    'code_input':code_input.val().trim()

                },
                success: function(res) {
                    if(res.code == 200 && res.data == 1) {
                        alert("登陆成功");
                        location.href = "myblog_list1.html";
                        return;
                    }else 
                        alert("登陆失败 : " + res.msg);
                        refreshCode();
                        jQuery("#submit-button").removeAttr("disabled");
                        return false;
                    
                }
            });

        }

        // function limitIp() {
        //     if(count >= 3) {
        //         jQuery.ajax({
        //             // 同质后端对当前用户进行拉黑
        //         });
        //     }
        // }
        // limitIp();

    </script>

</body>
 
</html>